//
//  MBDGroupContactsCellModel.swift
//  MasterBoy
//
//  Created by kyson on 2024/10/12.
//

import Foundation
import YYText


class MBDGroupContactsCellModel : MBDGroupDetailCommonCellModel {

    var groupContactsTitleLayout : YYTextLayout?

    var groupContactsTextLayout : YYTextLayout?
    
    static let MarginTop : CGFloat = 10
    static let MarginBottom : CGFloat = 10
    static let MarginBetweenTitleAndDetail : CGFloat = 8
    static let MarginBetweenIconAndDetail : CGFloat = 8
    static let IconSize : CGFloat = 16

    override init() {
        super.init()
        
        let groupDetailAttributeString = NSMutableAttributedString(string: "联系方式" )
        groupDetailAttributeString.yy_font = UIFont.boldSystemFont(ofSize: 16)
        groupDetailAttributeString.setDynamicTextColor()
        groupDetailAttributeString.yy_lineSpacing = 4
        
        let groupDetailContainer = YYTextContainer()
        
        let groupDetailWidth = CGRectGetWidth(UIScreen.main.bounds) - MBDGroupLogoCellModel.MarginLeftAndRightBackgroundView * 2
        groupDetailContainer.size = CGSizeMake(groupDetailWidth , CGFLOAT_MAX)
        let groupDetailLayout = YYTextLayout(container: groupDetailContainer, text: groupDetailAttributeString)
        
        self.groupContactsTitleLayout = groupDetailLayout
    }

    override var groupDetail: MBDGroupDetailModel! {
        didSet {
            let groupInfo = self.groupDetail.groupManager!
            let groupDetailAttributeString = NSMutableAttributedString(string: (groupInfo.isBlank ? "待解锁" : groupInfo) )
            groupDetailAttributeString.yy_font = UIFont.systemFont(ofSize: 14)
            groupDetailAttributeString.yy_lineSpacing = 4
            groupDetailAttributeString.setDynamicTextColor()

            let groupDetailContainer = YYTextContainer()
            
            let groupDetailWidth = CGRectGetWidth(UIScreen.main.bounds) - MBDGroupLogoCellModel.MarginLeftAndRightBackgroundView * 2
            groupDetailContainer.size = CGSizeMake(groupDetailWidth , CGFLOAT_MAX)
            let groupDetailLayout = YYTextLayout(container: groupDetailContainer, text: groupDetailAttributeString)
            
            self.groupContactsTextLayout = groupDetailLayout
        }
    }
    
    
    override func cellHeight() -> CGFloat {
        return MBDGroupContactsCellModel.MarginTop + (self.groupContactsTitleLayout?.textBoundingSize.height ?? 0) + MBDGroupContactsCellModel.MarginBetweenTitleAndDetail + (self.groupContactsTextLayout?.textBoundingSize.height ?? 0) + MBDGroupContactsCellModel.MarginBottom
    }
}
